﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using System.IO;

namespace LanguageStudy
{
    public partial class OPForm : Form
    {
        public OPForm(ArrayList alWord)
        {
            InitializeComponent();

            for (int _i = 0; _i < alWord.Count; _i++)
            {
                this.rtbShow.AppendText(alWord[_i].ToString() + "   ");
            }
        }

        private string m_strDirectory;
        private void btnSave_Click(object sender, EventArgs e)
        {
            SaveFileDialog dlgSaveFile = new SaveFileDialog();

            dlgSaveFile.InitialDirectory = m_strDirectory;
            dlgSaveFile.Filter = "文本文件 (*.txt)|*.txt";
            dlgSaveFile.FilterIndex = 1;
            dlgSaveFile.RestoreDirectory = true;

            if (dlgSaveFile.ShowDialog() == DialogResult.OK)
            {
                // 路径处理
                m_strDirectory = dlgSaveFile.FileName;

                // 写入文件
                try
                {
                    StreamWriter sw = new StreamWriter(dlgSaveFile.FileName);
                    sw.Write(this.rtbShow.Text);
                    sw.Close();
                }
                catch (System.Exception ex)
                {
                    System.Console.WriteLine(ex);
                }
            }
        }

        private void btnPageSetup_Click(object sender, EventArgs e)
        {
            PageSetupDialog psd = new PageSetupDialog();
            psd.ShowDialog();
        }

        private void btnPreview_Click(object sender, EventArgs e)
        {
            PrintPreviewDialog ppd = new PrintPreviewDialog();
            ppd.ShowDialog();
        }

        private void btnPrint_Click(object sender, EventArgs e)
        {
            PrintDialog pd = new PrintDialog();
            pd.UseEXDialog = true;
            pd.Document = this.printDocument;

            if (pd.ShowDialog() == DialogResult.OK)
            {
//                 this.printDocument.Print();
            }
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void printDocument_BeginPrint(object sender, System.Drawing.Printing.PrintEventArgs e)
        {

        }

        private void printDocument_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            e.Graphics.DrawString(this.rtbShow.Text, new Font("Arial", 10), Brushes.Black, 0, 0);
        }

        private void printDocument_EndPrint(object sender, System.Drawing.Printing.PrintEventArgs e)
        {

        }
    }
}
